﻿/*
--------------------------------------
File: Batch.cs
Project: Themaopdracht 7
Author: Maarten Kroon & Thierry Gerritse

Description:
A batch that can perform several vision algoritms in a row
--------------------------------------
*/

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace THO7_Team8
{
	public class Batch : VisionAlgorithm
	{
		public Batch(String name)
			: base(name)
		{
		}

		public override Bitmap DoAlgorithm(Bitmap sourceImage)
		{
			//SimpleColorDetect checks for yellowpixels in the image
			SimpleColorDetectMonogrome simpleColorDetectMonochrome = new SimpleColorDetectMonogrome("");
			Bitmap simpleColorDetectMonochromeResult1 = simpleColorDetectMonochrome.DoAlgorithm(sourceImage);

			//BlobDetection to filter small blobs, multiple blobs and blobs which do not have the right dimensions
			LicensePlateBlobDetection licensePlateBlobDetection = new LicensePlateBlobDetection("");
			Bitmap licensePlateBlobDetectionResult = licensePlateBlobDetection.DoAlgorithm(simpleColorDetectMonochromeResult1);

			//Crop license plate and returns the original colors
			//This is needed to return the small black spaces in letters
			//CropLicenseplate cropLicensePlate = new CropLicenseplate("");
			//Bitmap cropLicensePlateResult = cropLicensePlate.DoAlgorithm(licensePlateBlobDetectionResult);

			CropLicenseplateColoured cropLicensePlateColored = new CropLicenseplateColoured("");
			Bitmap cropLicensePlateColoredResult = cropLicensePlateColored.CropLicensePlateFromOriginal(licensePlateBlobDetectionResult, sourceImage);

			MakeMonochrome makeMonochrome = new MakeMonochrome("");
			Bitmap makeMonochromeResult = makeMonochrome.DoAlgorithm(cropLicensePlateColoredResult);

			CropEdges cropEdges = new CropEdges("");
			Bitmap cropEdgesResult = cropEdges.DoAlgorithm(makeMonochromeResult);

			//Bitmap binaryResult = Binair.RunBitmapAlgorithm(cropLicensePlateColoredResult);
			Bitmap rotatePlateResult = RotatePlate.run(cropEdgesResult);

			//Performs again a simple color detect to show only the license plate
			//SimpleColorDetectMonogrome colorDetect2 = new SimpleColorDetectMonogrome("");
			//Bitmap simpleColorDetectResult2 = simpleColorDetectMonochrome.DoAlgorithm(CropLicensePlateColoredResult);

			//Rotate the license plate
			//RotateLicensePlate rotateLicensePlate = new RotateLicensePlate("");
			//Bitmap rotateLicensePlateResult = rotateLicensePlate.DoAlgorithm(cropLicensePlateResult);

			if(rotatePlateResult != null)
			{
				return rotatePlateResult;
			}
			else
			{
				//MessageBox.Show("Geen bruikbaar resultaat gevonden");
				return null;
			}
		}
	}
}
